#include "FKPacker.h"
#include <QByteArray>
#include "FKSystemObject.h"
#include <QDataStream>

QByteArray FKPacker::pack(QString messageType, FKSystemObject* obj){
    QByteArray arr;
    QDataStream stream(&arr, QIODevice::WriteOnly);
    stream.setVersion(QDataStream::Qt_5_0);
    stream<<messageType;
    obj->packObject(stream);
    return arr;
}

QString FKPacker::unpack(QByteArray arr, FKSystemObject* &container){
    if(container)return FKPacker::error;
    QDataStream stream(&arr, QIODevice::ReadOnly);
    stream.setVersion(QDataStream::Qt_5_0);
    QString type;
    stream>>type;
    container=FKSystemObject::loadObject(stream);
    if(!container)type=FKPacker::error;
    return type;
}
